import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { YixiantongModule } from './yixiantong/yixiantong.module';
import {
  YixianTongFields,
  YixiantongFieldsGoods,
  YixiantongFieldsGoodsService,
} from './entities/yixiantong';
import { EnvConfigManager } from './utils/env-config-manager';
import { YixiantongGoodsModule } from './yixiantong-goods/yixiantong-goods.module';
import { YixiantongCitiesModule } from './yixiantong-cities/yixiantong-cities.module';
import { YixiantongGoodsServicesModule } from './yixiantong-goods-services/yixiantong-goods-services.module';

const envConfig = new EnvConfigManager().getConfig();

@Module({
  imports: [
    YixiantongModule,
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: envConfig.db_host,
      port: Number(envConfig.db_port),
      username: envConfig.db_user,
      password: envConfig.db_password,
      database: envConfig.db_name,
      entities: [YixianTongFields, YixiantongFieldsGoods, YixiantongFieldsGoodsService],
      synchronize: true, // 生产环境不要用这个参数！
      // autoLoadEntities: true, // 自动加载实体
    }),
    YixiantongGoodsModule,
    YixiantongCitiesModule,
    YixiantongGoodsServicesModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
